<script setup lang='ts'>
import { ref } from "vue";
import {useRouter} from "vue-router";
import {  showFailToast } from 'vant';
const router = useRouter()
const value = ref('');
const searchData = ref<{}[]>([]);
const onSearch = (val: string) => {
    if(val === '') return showFailToast('请输入查询的内容');
    
    if (localStorage.getItem('searchData') !== null && localStorage.getItem('searchData') !== '') {
        searchData.value = JSON.parse(localStorage.getItem('searchData') as string)
    }
    searchData.value.push({ title: val })
    localStorage.setItem('searchData', JSON.stringify(searchData.value)) 
    router.push({name:'ThisData',query:{type:val}})
}
</script>

<template>
    <form action="/">
        <van-search v-model="value" show-action placeholder="请输入搜索关键词" @search="onSearch" />
    </form>
</template>

<style scoped></style>